<?php

namespace common\models\user;

use common\behaviors\MerchantBehavior;
use common\models\firstpage\Address;
/**
 * This is the model class for table "{{%oauth_client}}".
 *
 * @property string $id
 * @property string $title 标题
 * @property string $client_id
 * @property string $client_secret
 * @property string $redirect_uri 回调Url
 * @property string $remark 备注
 * @property string $group 组别
 * @property int $status 状态[-1:删除;0:禁用;1启用]
 * @property string $created_at 创建时间
 * @property string $updated_at 修改时间
 */
class Shoporder extends \common\models\base\BaseModel
{
   // use MerchantBehavior;

    /**
     * {@inheritdoc}
     */
    //public $name;
    public static function tableName()
    {
        return '{{%by_shop_order}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
//            [['client_id'], 'unique'],
            [[
                'product',//商品名称
                'user_id',//用户id
                'site_id',//用户地址id
                'integral',//商品需要积分
                'type'
            ], 'safe'],
            [[ 'status', 'created_at', 'updated_at'], 'integer'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'ordernumber'=>'订单编号',
            'product'=>'商品名称',
            'user_id'=>'用户名称',
            'site_id'=>'用户地址',
            'integral'=>'商品需要积分',
            'type'=>'当前状态',
            'status' => '状态',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
        ];
    }

    public function getCate()
    {
        return $this->hasOne(Member::class, ['id' => 'user_id']);
    }
    public function getCates()
    {
        return $this->hasOne(Comm::class, ['id' => 'product']);
    }

    public function getCatss()
    {
        return $this->hasOne(Address::class, ['id' => 'site_id'])->join('join','rf_common_provinces a','a.id=rf_by_address.province_id')->select('rf_by_address.*,a.title titles');
    }
    public function getCatss1()
    {
        return $this->hasOne(Address::class, ['id' => 'site_id'])->join('join','rf_common_provinces a','a.id=rf_by_address.city_id')->select('rf_by_address.*,a.title title1');
    }
    public function getCatss2()
    {
        return $this->hasOne(Address::class, ['id' => 'site_id'])->join('join','rf_common_provinces a','a.id=rf_by_address.area_id')->select('rf_by_address.*,a.title title2');
    }
}